package learningtests;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;

public class DataOutputStreamLearning {

    @Test
    public void testDataOutputStreamWriteOffset() {
        String discardedContent = "This is discarded";
        String outputContent = "This is the outputcontent";

        String testOutputContent = discardedContent + outputContent;

        File outputFile = new File("c:/test/testOutputWriteOffset.txt");
        try {
            DataOutputStream writer = makeWriter(outputFile);
            writer.write(testOutputContent.getBytes(), discardedContent.length(), outputContent.length());
        } catch (FileNotFoundException fnf) {
            throw new RuntimeException(fnf);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    private DataOutputStream makeWriter(File file) throws FileNotFoundException {
        FileOutputStream rawStream = new FileOutputStream(file);
        DataOutputStream writer = new DataOutputStream(rawStream);
        return writer;
    }
}
